starter.controller('ordersController', function($rootScope,$state,$ionicPopup,$ionicHistory,$timeout,$scope,Page, localStore,$location) {

	//默认查询待支付订单
	$scope.searchOrder = function(status) {
		Page.ajaxPost('app/order/toBePaid.do',{status : status}, function(resp) {
			$scope.orderList = resp.data;
		});
	};

	$scope.clickTab = function(index) {
		if("1" == index) {
			$scope.searchOrder(index); //点击tab,进行相关查询
		} else if("2" == index) { //查询已支付
			Page.ajaxPost('app/order/hadPaid.do',{status : index}, function(resp) {
				$scope.orderList = resp.data;
			});
		} else if("3" == index) {
			Page.ajaxPost('app/orderBack/getOrderBackByPhone.do',{status : index}, function(resp) {
				$scope.orderList = resp.data;
			});
		}
	};

	$scope.toPay = function(order) {
		$state.go("order_toPay",{orderId : order.orderId});
	};

	$scope.refundDetail = function(order) {
		$state.go("refund_detail",{orderBackId : order.orderBackId});
	};

	$scope.cancelOrder = function(order){
		Page.confirm('您确认取消该订单?',function(){
			Page.ajaxPost('order/cancel.do',{orderId : order.orderId}, function(resp) {
				Page.notice("操作成功!");
				$scope.searchOrder("1");
			});
		});
	};

	$scope.toHadPay = function(order) {
		$state.go("order_hadPay",{orderId : order.orderId});
	};

	$scope.toRefund = function(order) {
		$state.go("refund",{orderId : order.orderId});
	};

	$scope.payNow = function(order) {
		$state.go("order_pay",{orderId : order.orderId});
	};

	$scope.backGo = function (){
		$ionicHistory.clearHistory();
		$state.go('home');
	};
		
});